package algorithm.recursionAndbacktrack.combination;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author CandyWall
 * @Date 2022/2/3--13:40
 * @Description
 */
public class CombinationTest {
    private ArrayList<List<Integer>> combinations;

    public List<List<Integer>> getCombinations(int[] nums) {
        combinations = new ArrayList<>();
        if (nums != null && nums.length > 0) {
            getCombinations(nums, 0, new ArrayList<Integer>());
        }
        return combinations;
    }

    private void getCombinations(int[] nums, int index, ArrayList<Integer> combination) {
        if (combination.size() == 2) {
            combinations.add(new ArrayList<>(combination));
            return;
        }

        for (int i = index; i < nums.length; i++) {
            combination.add(nums[i]);
            getCombinations(nums, i + 1, combination);
            combination.remove(combination.size() - 1);
        }
    }

    public static void main(String[] args) {
        System.out.println(new CombinationTest().getCombinations(new int[] {1, 2, 3, 4, 5}));
    }
}
